package com.example.service.impl;

import com.example.dao.IRoleDao;
import com.example.domain.Permission;
import com.example.domain.Role;
import com.example.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Date: 2021年08月21日 18:46
 * @Author: LHSAMA
 */
@Service
public class RoleServiceImpl implements IRoleService {

    @Autowired
    private IRoleDao roleDao;

    @Override
    public List<Role> findAll() {
        return roleDao.findAll();
    }

    @Override
    public void save(Role role) {
        roleDao.save(role);
    }

    @Override
    public Role findById(String id) {
        return roleDao.findById(id);
    }

    @Override
    public void deleteRole(String id) {
        roleDao.deleteRolePermission(id);
        roleDao.deleteUsersRole(id);
        roleDao.deleteRole(id);
    }

    @Override
    public List<Permission> findOtherPermissions(String id) {
        return roleDao.findOtherPermissions(id);
    }

    @Override
    public void addPermissionToRole(String roleId, String[] permissionIdList) {
        for (String permissionId : permissionIdList) {
            roleDao.savePermissionToRole(roleId,permissionId);
        }
    }
}
